import Vue from 'vue'
import Router from 'vue-router'
import {beforeEach} from '@/assets/js/common/router.com.js'

Vue.use(Router)

let _base = 'tenFair/view';

process.env.VERSION ? _base += `/${process.env.VERSION}` : '';

const router = new Router({
    mode: 'history',
    base: _base,
    routes: [
        // 店铺详情页
        {
            path: `/shopDetail(.*)+`,
            name: 'tenFairShopDetail',
            component: resolve => require(['../pages/shopDetail.vue'], resolve),
            meta: {
                requireAuth: true, // 判断是否需要登录
                title: sessionStorage.getItem('fissile_shopName')
            }
        },
        // 商品详情页
        {
            path: `/goodsDetail(.*)+`,
            name: 'tenFairGoods',
            component: resolve => require(['../pages/goodsDetail.vue'], resolve),
            meta: {
                requireAuth: true, // 判断是否需要登录
                title: '十元五件集市'
            }
        },
        // 首页、店铺列表页(无路由匹配都进入这个页面)
        {
            path: `*(.*)+`,
            name: 'tenFairShopList',
            component: resolve => require(['../pages/shopList.vue'], resolve),
            meta: {
                requireAuth: true, // 判断是否需要登录
                title: '十元五件集市'
            }
        },
    ],
    scrollBehavior (to, from, savedPosition) {
        if (savedPosition) {
            console.log(savedPosition)
          return savedPosition
        } else {
          return { x: 0, y: 0 }
        }
    }
})

let _temp = false;

router.beforeEach((to, from, next) => {
    beforeEach(to, from, next, _temp, _base, function(){
        _temp = true;
    });
    
})

export default router;
